package
{
	import com.evola.dbsm.commands.CreateProjectCommand;
	import com.evola.dbsm.commands.CreateScriptCommand;
	import com.evola.dbsm.commands.LoadProjectsCommand;
	import com.evola.dbsm.commands.LoadScriptsCommand;
	import com.evola.dbsm.commands.StartupCommand;
	import com.evola.dbsm.commands.UpdateProjectCommand;
	import com.evola.dbsm.commands.UpdateScriptCommand;
	import com.evola.dbsm.service.impl.ProjectsService;
	import com.evola.dbsm.service.impl.ScriptService;
	import com.evola.dbsm.view.navigation.NavigationPresenter;
	import com.evola.dbsm.view.navigation.NavigationView;
	import com.evola.dbsm.view.project.edit.ProjectEditEvent;
	import com.evola.dbsm.view.project.edit.ProjectEditPresenter;
	import com.evola.dbsm.view.project.edit.ProjectEditModel;
	import com.evola.dbsm.view.project.edit.ProjectEditView;
	import com.evola.dbsm.view.project.list.ProjectListEvent;
	import com.evola.dbsm.view.project.list.ProjectListPresenter;
	import com.evola.dbsm.view.project.list.ProjectListModel;
	import com.evola.dbsm.view.project.list.ProjectListView;
	import com.evola.dbsm.view.script.edit.ScriptEditEvent;
	import com.evola.dbsm.view.script.edit.ScriptEditPresenter;
	import com.evola.dbsm.view.script.edit.ScriptEditModel;
	import com.evola.dbsm.view.script.edit.ScriptEditView;
	import com.evola.dbsm.view.script.list.ScriptListEvent;
	import com.evola.dbsm.view.script.list.ScriptListPresenter;
	import com.evola.dbsm.view.script.list.ScriptListModel;
	import com.evola.dbsm.view.script.list.ScriptListView;
	
	import flash.display.DisplayObjectContainer;
	
	import org.robotlegs.base.ContextEvent;
	import org.robotlegs.mvcs.Context;

	public class EvolaDBScriptManagerContext extends Context
	{
		public function EvolaDBScriptManagerContext(contextView:DisplayObjectContainer=null, autoStartup:Boolean=true)
		{
			super(contextView, autoStartup);
		}

		override public function startup():void
		{

			//Commands
			commandMap.mapEvent(ContextEvent.STARTUP, StartupCommand, ContextEvent);
			commandMap.mapEvent(ProjectListEvent.LOAD_PROJECTS, LoadProjectsCommand, ProjectListEvent);
			commandMap.mapEvent(ScriptListEvent.LOAD_SCRIPTS, LoadScriptsCommand, ScriptListEvent);

			commandMap.mapEvent(ProjectEditEvent.PROJECT_EDIT_ADD, CreateProjectCommand, ProjectEditEvent);
			commandMap.mapEvent(ProjectEditEvent.PROJECT_EDIT_EDIT, UpdateProjectCommand, ProjectEditEvent);

			commandMap.mapEvent(ScriptEditEvent.SCRIPT_EDIT_ADD, CreateScriptCommand, ScriptEditEvent);
			commandMap.mapEvent(ScriptEditEvent.SCRIPT_EDIT_EDIT, UpdateScriptCommand, ScriptEditEvent);

			//Services
			injector.mapSingleton(ProjectsService);
			injector.mapSingleton(ScriptService);

			//Models
			injector.mapSingleton(ProjectListModel);
			injector.mapSingleton(ScriptListModel);
			injector.mapSingleton(ProjectEditModel);
			injector.mapSingleton(ScriptEditModel);

			//Views
			mediatorMap.mapView(NavigationView, NavigationPresenter);
			mediatorMap.mapView(ProjectListView, ProjectListPresenter);
			mediatorMap.mapView(ScriptListView, ScriptListPresenter);
			mediatorMap.mapView(ProjectEditView, ProjectEditPresenter);
			mediatorMap.mapView(ScriptEditView, ScriptEditPresenter);

			//pokrecemo ucitavanje projekata
			dispatchEvent(new ContextEvent(ContextEvent.STARTUP));

			super.startup();

		}
	}
}